package com.star.result;

import org.springframework.http.HttpStatus;

/**
 * 接口模型
 *
 * @author tanyapeng
 */
public class API {
    /**
     * ok
     *
     * @return
     */
    public static ApiRes ok() {
        return ok(null);
    }

    /**
     * ok
     *
     * @param payload
     * @return
     */
    public static ApiRes ok(Object payload) {
        ApiRes response = new ApiRes();
        response.setSuccess(true);
        response.setErrorCode(HttpStatus.OK.value());
        response.setErrorMessage(HttpStatus.OK.getReasonPhrase());
        response.setPayload(payload);
        return response;
    }

    /**
     * error
     *
     * @return
     */
    public static ApiRes error() {
        return error(HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase());
    }

    /**
     * error
     *
     * @param errorMessage
     * @return
     */
    public static ApiRes error(String errorMessage) {
        return error(HttpStatus.INTERNAL_SERVER_ERROR.value(), errorMessage);
    }

    /**
     * error
     *
     * @param errorCode
     * @param errorMessage
     * @return
     */
    public static ApiRes error(int errorCode, String errorMessage) {
        ApiRes response = new ApiRes();
        response.setSuccess(false);
        response.setErrorCode(errorCode);
        response.setErrorMessage(errorMessage);
        return response;
    }
}
